/*
 * @Author: Zhao Star
 * @LastEditors: Zhao Star
 * @Description: *******************
 * @Date: 2019-04-29 09:35:16
 * @LastEditTime: 2019-05-06 16:54:31
 */
import axios from 'axios'
// import { getToken } from '@/utils/auth'
// axios.defaults.headers.post['Content-Type'] = 'application/x-www-form-urlencoded'
const service = axios.create({
  baseURL: 'http://118.24.222.112:3000',
  withCredentials: true,
  timeout: 5000
})
service.interceptors.request.use(
  (config) => {
    // config.headers['X-Token'] = getToken()
    return config
  },
  (error) => {
    console.log(error)
    return Promise.reject(error)
  }
)

service.interceptors.response.use(
  (response) => {
    const res = response.data
    if (res.code !== 200) {
      console.log('出错了')
      return res
    } else {
      return res
    }
  },
  (error) => {
    console.log('err' + error)
    console.log('接口未请求成功')
    return Promise.reject(error)
  }
)

export default service
